// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
  for (var a = 0; a <= event.value.length - 1; a++) {
    let i = await cloud.database().collection('song').doc(event.value[a].id).get()
    if (i.data.likes > event.value[a].likes) {
      return
    } else {
      cloud.database().collection('song').doc(event.value[a].id)
        .update({
          data: {
            likes: event.value[a].likes
          }
        })
    }
  }
}